﻿<Page
    x:Class="FunstreamTV.StreamPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="{Binding StreamViewModel,RelativeSource={RelativeSource Self}}"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:converters="using:FunstreamTV.Converters"
    xmlns:mpf="using:Microsoft.PlayerFramework"
    xmlns:smmp="using:SM.Media.MediaPlayer"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton x:Uid="PlayerAppButton" Icon="Play" Click="SettingsClick" Visibility="{Binding PlayerButtonVisibility}"/>
            <AppBarButton x:Uid="ChatAppButton" Icon="Message" Click="ChatClick" Visibility="{Binding ChatButtonVisibility}"/>
            <AppBarButton x:Uid="SendAppButton" Icon="Send" Click="SendClick" Visibility="{Binding SmilesButtonVisibility}"/>
            <AppBarButton x:Uid="SmilesAppButton" Icon="Emoji2" Click="SmilesClick" Visibility="{Binding SmilesButtonVisibility}"/>
            <AppBarButton x:Uid="StreamerMessageAppButton" Icon="Contact" Click="StreamerAsRecipient" Visibility="{Binding SmilesButtonVisibility}" />
        </CommandBar>
    </Page.BottomAppBar>
    <Page.Resources>
        <ResourceDictionary>
            <converters:TextToRichConverter x:Key="TextToRichConverter" />
        </ResourceDictionary>
    </Page.Resources>

    <Grid>

        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="1" >
            <mpf:MediaPlayer Source="{Binding StreamUri}" AudioCategory="BackgroundCapableMedia" IsAudioSelectionVisible="True" Visibility="{Binding PlayerVisibility}">
                <mpf:MediaPlayer.Plugins>
                    <smmp:StreamingMediaPlugin />
                </mpf:MediaPlayer.Plugins>
            </mpf:MediaPlayer>      
            <Grid Visibility="{Binding ChatVisibility}" Background="#50000000">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ListView ItemsSource="{Binding Messages}" Name="ChatListView" IsItemClickEnabled="True" ItemClick="ChatMessageClick">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="10" Background="#70FFFFFF">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <StackPanel Orientation="Horizontal" Margin="5">
                                    <TextBlock Text="{Binding from.name}" FontSize="18" Foreground="{Binding FromNickColor}"/>
                                    <TextBlock Text="->" FontSize="18" Visibility="{Binding ToArrowVisibility}"/>
                                    <TextBlock Text="{Binding to.name}" FontSize="18"/>
                                </StackPanel>
                                <ContentControl Grid.Row="2" Content="{Binding text, Converter={StaticResource TextToRichConverter}}"/>
                                <TextBlock Grid.Row="3" Text="{Binding time}" Margin="5"/>
                            </Grid>

                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <TextBlock Grid.Row="1" FontSize="20" Margin="0,10,0,10" Text="{Binding Recipient.name}" Tapped="RecipientRemove" Visibility="{Binding RecipientVisibility}"/>
                <TextBox Grid.Row="2" Text="{Binding Message, Mode=TwoWay}" HorizontalAlignment="Stretch" KeyUp="MessageTextBoxKeyUp"/>
            </Grid>
            <Grid Visibility="{Binding SmilesVisibility}">
                <Pivot>
                    <PivotItem>
                        <GridView ItemsSource="{Binding Smiles[0]}" IsItemClickEnabled="True" ItemClick="SmileClick">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding FullUri}" Width="60" Height="60" Margin="2.5" />
                                </DataTemplate>
                            </GridView.ItemTemplate>
                        </GridView>
                    </PivotItem>
                    <PivotItem>
                        <GridView ItemsSource="{Binding Smiles[1]}" IsItemClickEnabled="True" ItemClick="SmileClick">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding FullUri}"  Width="60" Height="60" Margin="2.5"/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
                        </GridView>
                    </PivotItem>
                    <PivotItem>
                        <GridView ItemsSource="{Binding Smiles[2]}" IsItemClickEnabled="True" ItemClick="SmileClick">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding FullUri}"  Width="60" Height="60" Margin="2.5"/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
                        </GridView>
                    </PivotItem>
                    <PivotItem>
                        <GridView ItemsSource="{Binding Smiles[3]}" IsItemClickEnabled="True" ItemClick="SmileClick">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding FullUri}"  Width="60" Height="60" Margin="2.5"/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
                        </GridView>
                    </PivotItem>
                    <PivotItem>
                        <GridView ItemsSource="{Binding Smiles[4]}" IsItemClickEnabled="True" ItemClick="SmileClick">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding FullUri}"  Width="60" Height="60" Margin="2.5"/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
                        </GridView>
                    </PivotItem>
                    <PivotItem>
                        <GridView ItemsSource="{Binding Smiles[5]}" IsItemClickEnabled="True" ItemClick="SmileClick">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding FullUri}"  Width="60" Height="60" Margin="2.5"/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
                        </GridView>
                    </PivotItem>
                </Pivot>
            </Grid>
            <Grid Visibility="{Binding SettingsVisibility}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ComboBox x:Uid="StreamPagePlayerSelect" ItemsSource="{Binding Players}" SelectionChanged="PlayerSelected" Margin="0,0,0,10" >
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding name}" FontSize="20"/>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <ComboBox Grid.Row="1" x:Uid="StreamPageQualitySelect" ItemsSource="{Binding Playlist}" SelectionChanged="QualitySelected" >
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Quality}" FontSize="20"/>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </Grid>
        </Grid>
    </Grid>
</Page>
